package cc.eddic.practice.spring.domain;

import cc.eddic.practice.spring.QuestionType;
import cc.eddic.practice.spring.jpa.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.List;


@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "t_question")
@Builder
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Question extends BaseEntity {

    @Column(length = 50)
    private int no;

    @Column(length = 50)
    private String description;

    @Column(length = 50)
    private QuestionType questionType;

    @JsonIgnore
    @ToString.Exclude
    @OneToMany(mappedBy = "question",cascade = CascadeType.ALL,fetch = FetchType.LAZY) //？
    private List<Option> options;

    public Question(int no,String description,QuestionType questionType){
        this.no=no;
        this.description=description;
        this.questionType=questionType;
    }

    public Question add(Option option){
        option.setQuestion(this);
        options.add(option);
        return this;
    }
}
